home *** CD-ROM | disk | FTP | other *** search
/ MacHack 2000 / MacHack 2000.toast / pc / The Hacks / Vertigo / NubApp / Window.cc < prev    next >
Encoding:
C/C++ Source or Header  |  2000-06-24  |  15.2 KB  |  1,089 lines

  1. #define DISABLE_LOCAL_CALLTRACE        1        // Set to 1 to disable Call Traces for this file.
  2. #define DISABLE_LOCAL_DEBUG            0        // Set to 1 to disable all debugging for this file.
  3. #include "DebugUtils.h"
  4.  
  5. #include <Controls.h>
  6. #include <Dialogs.h>
  7. #include <stdarg.h>
  8. #include <stdio.h>
  9. #include <stdlib.h>
  10. #include <string.h>
  11. #include "Menu.h"
  12. #include "QDUtils.h"
  13. #include "Window.h"
  14.  
  15.  
  16.  
  17.  
  18.  
  19. enum
  20. {
  21.     kOKButtonID                = 1,
  22.     kCancelButtonID            = 2
  23. };
  24.  
  25.  
  26.  
  27.  
  28.  
  29. extern MenuManager                    *gMenuManager;
  30. extern WindowManager                *gWindowManager;
  31.  
  32.  
  33.  
  34.  
  35.  
  36. BaseWindowManager::BaseWindowManager(void)
  37. {
  38.     fSuspended = false;
  39. }
  40.  
  41.  
  42.  
  43.  
  44.  
  45. BaseWindowObject *BaseWindowManager::GetWindowObject(WindowPtr window)
  46. {
  47.     BaseWindowObject    *obj;
  48.     
  49.     
  50.     obj = fWindowList.GetFirst();
  51.     while(obj && (obj->fWindowID != window))
  52.         obj = obj->next;
  53.     
  54.     return obj;
  55. }
  56.  
  57.  
  58.  
  59.  
  60.  
  61. void BaseWindowManager::DoAddWindow(Window *window)
  62. {
  63.     BaseWindowObject    *obj;
  64.     
  65.     
  66.     obj = new BaseWindowObject;
  67.     if (obj != NULL)
  68.     {
  69.         obj->fWindowID = window->fWindow;
  70.         obj->fWindowObject = window;
  71.         fWindowList.Append(obj);
  72.         gMenuManager->DoWindowNotice(window,true);
  73.     }
  74. }
  75.  
  76.  
  77.  
  78.  
  79.  
  80. void BaseWindowManager::DoDeleteWindow(Window *window)
  81. {
  82.     BaseWindowObject    *obj;
  83.     
  84.     
  85.     obj = GetWindowObject(window->fWindow);
  86.     if (obj != NULL)
  87.     {
  88.         gMenuManager->DoWindowNotice(window,false);
  89.         fWindowList.Delete(obj);
  90.         delete obj;    
  91.     }
  92. }
  93.  
  94.  
  95.  
  96.  
  97.  
  98. void BaseWindowManager::DoClick(Point where,UInt32 modifiers,WindowPtr window,SInt32 part)
  99. {
  100.     Window    *win = DoGetWindow(window);
  101.     Window    *top;
  102.     
  103.     
  104.     // Don't let any other window have input or be able
  105.     // to layer switch if a modal dialog is the topmost
  106.     top = DoGetFrontWindow();
  107.     if ((win != top) && ((top->fFlags & (kDialog | kModal)) == (kDialog | kModal)))
  108.         return;
  109.     
  110.     if (win != NULL)
  111.         win->DoClick(where,modifiers,part);
  112. }
  113.  
  114.  
  115.  
  116.  
  117.  
  118. void BaseWindowManager::DoIdleTime(EventRecord *event,Point mouse,UInt32 modifiers)
  119. {
  120.     BaseWindowObject    *obj;
  121.     WindowPtr            window;
  122.     Window                *win;
  123.     SInt32                part;
  124.     
  125.     
  126.     if (!fSuspended)
  127.     {
  128.         win = NULL;
  129.         part = FindWindow(mouse,&window);
  130.         if (part == inContent)
  131.         {
  132.             win = DoGetWindow(window);
  133.             if ((win != NULL) && (win->fFlags & kActive))
  134.                 win->DoUpdateCursor(mouse,modifiers);
  135.             else
  136.                 win = NULL;
  137.         }
  138.         
  139.         if (win == NULL)
  140.             SetCursor(&qd.arrow);
  141.     }
  142.     
  143.     obj = fWindowList.GetFirst();
  144.     while(obj != NULL)
  145.     {
  146.         obj->fWindowObject->DoIdleTime(event,mouse,modifiers);
  147.         obj = obj->next;
  148.     }
  149. }
  150.  
  151.  
  152.  
  153.  
  154.  
  155. void BaseWindowManager::DoActivation(WindowPtr window,Boolean isActivating)
  156. {
  157.     Window    *win;
  158.     
  159.     
  160.     win = DoGetWindow(window);
  161.     if (win != NULL)
  162.     {
  163.         win->DoSetActivationState(isActivating);
  164.         gMenuManager->DoWindowActivation(win,isActivating);
  165.     }
  166. }
  167.  
  168.  
  169.  
  170.  
  171.  
  172. void BaseWindowManager::DoSuspendResume(EventRecord *event,Boolean isSuspend)
  173. {
  174.     BaseWindowObject    *obj;
  175.     
  176.     
  177.     obj = fWindowList.GetFirst();
  178.     while(obj != NULL)
  179.     {
  180.         obj->fWindowObject->DoSetSuspensionState(event,isSuspend);
  181.         obj = obj->next;
  182.     }
  183.     
  184.     fSuspended = isSuspend;
  185. }
  186.  
  187.  
  188.  
  189.  
  190.  
  191. Window *BaseWindowManager::DoGetFrontWindow(void)
  192. {
  193.     WindowPtr    window;
  194.     Window        *win;
  195.     
  196.     
  197.     // Floating windows are system windows
  198.     // do this actually is correct
  199.     window = FrontWindow();
  200.     while(window != NULL)
  201.     {
  202.         if (((WindowPeek)window)->visible)
  203.         {
  204.             win = DoGetWindow(window);
  205.             if (win != NULL)
  206.                 return win;
  207.         }
  208.         
  209.         window = (WindowPtr)((WindowPeek)window)->nextWindow;
  210.     }
  211.     
  212.     return NULL;
  213. }
  214.  
  215.  
  216.  
  217.  
  218.  
  219. Window *BaseWindowManager::DoGetNextWindow(Window *window)
  220. {
  221.     WindowPtr    next;
  222.     
  223.     
  224.     next = (WindowPtr)((WindowPeek)window->fWindow)->nextWindow;
  225.     while(next != NULL)
  226.     {
  227.         window = DoGetWindow(next);
  228.         if ((window != NULL) && ((WindowPeek)window)->visible)
  229.             return window;
  230.         
  231.         next = (WindowPtr)((WindowPeek)next)->nextWindow;
  232.     }
  233.     
  234.     return NULL;
  235. }
  236.  
  237.  
  238.  
  239.  
  240.  
  241. Window *BaseWindowManager::DoGetWindow(WindowPtr window)
  242. {
  243.     BaseWindowObject    *obj;
  244.     
  245.     
  246.     obj = GetWindowObject(window);
  247.     return obj ? obj->fWindowObject : NULL;
  248. }
  249.  
  250.  
  251.  
  252.  
  253.  
  254. // Do nothing constructor varient
  255. BaseWindow::BaseWindow(void)
  256. {
  257.     
  258. }
  259.  
  260.  
  261.  
  262.  
  263.  
  264. // Resource based window constructor varient
  265. BaseWindow::BaseWindow(UInt32 windowID)
  266. {
  267.     fWindow = ::GetNewCWindow(windowID,NULL,(WindowPtr)-1L);
  268.     if (fWindow != NULL)
  269.     {
  270.         fFlags = 0L;
  271.         gWindowManager->DoAddWindow(this);
  272.     }
  273. }
  274.  
  275.  
  276.  
  277.  
  278.  
  279. // Runtime based window constructor varient
  280. BaseWindow::BaseWindow(Boolean isFloatingWindow,short procID,Boolean goAwayFlag)
  281. {
  282.     Rect    bounds;
  283.     
  284.     
  285.     SetRect(&bounds,32,48,160,144);
  286.     if (isFloatingWindow)
  287.     {
  288.         dprintf(kDConPrefix "What, you think we do everything?\n");
  289.     }
  290.     else
  291.     {
  292.         fWindow = NewCWindow(    NULL,
  293.                                 &bounds,
  294.                                 "\p",
  295.                                 false,
  296.                                 procID,
  297.                                 (WindowPtr)(-1L),
  298.                                 goAwayFlag,
  299.                                 0L);
  300.         
  301.         if (fWindow != NULL)
  302.         {
  303.             fFlags = 0L;
  304.             gWindowManager->DoAddWindow(this);
  305.         }
  306.     }
  307. }
  308.  
  309.  
  310.  
  311.  
  312.  
  313. BaseWindow::~BaseWindow(void)
  314. {
  315.     if (fWindow != NULL)
  316.     {
  317.         gWindowManager->DoDeleteWindow(this);
  318.         if (fFlags & kFloater)
  319.         {
  320.             
  321.         }
  322.         else
  323.             DisposeWindow(fWindow);
  324.         fWindow = NULL;
  325.     }
  326. }
  327.  
  328.  
  329.  
  330.  
  331.  
  332. Boolean BaseWindow::DoGetParam(OSType param,SInt32 *value)
  333. {
  334.     return HandleGetParam(param,value);
  335. }
  336.  
  337.  
  338.  
  339.  
  340.  
  341. Boolean BaseWindow::DoSetParam(OSType param,SInt32 value)
  342. {
  343.     QDContext    context(fWindow);
  344.     
  345.     
  346.     return HandleSetParam(param,value);
  347. }
  348.  
  349.  
  350.  
  351.  
  352.  
  353. void BaseWindow::DoDialogEvent(EventRecord *event)
  354. {
  355.     DialogPtr    dialog;
  356.     short        item;
  357.     
  358.     
  359.     // Were really not a dialog...but
  360.     // lets do the right thing anyway
  361.     DialogSelect(event,&dialog,&item);
  362. }
  363.  
  364.  
  365.  
  366.  
  367.  
  368. void BaseWindow::DoClose(void)
  369. {
  370.     QDContext    context(fWindow);
  371.     
  372.     
  373.     HandleClose();
  374. }
  375.  
  376.  
  377.  
  378.  
  379.  
  380. void BaseWindow::DoKey(UInt32 key,UInt32 modifiers)
  381. {
  382.     QDContext    context(fWindow);
  383.     
  384.     
  385.     HandleKey(key,modifiers);
  386. }
  387.  
  388.  
  389.  
  390.  
  391.  
  392. void BaseWindow::DoClick(Point where,UInt32 modifiers,SInt32 part)
  393. {
  394.     QDContext    context(fWindow);
  395.     
  396.     
  397.     switch(part)
  398.     {
  399.         case inContent:
  400.             if (!(fFlags & (kActive | kFloater)))
  401.                 SelectWindow(fWindow);
  402.             else
  403.             {
  404.                 GlobalToLocal(&where);
  405.                 HandleClick(where,modifiers);
  406.             }
  407.             break;
  408.         
  409.         case inDrag:
  410.             HandleDrag(where);
  411.             break;
  412.         
  413.         case inGrow:
  414.             HandleGrow(where);
  415.             break;
  416.         
  417.         case inGoAway:
  418.             if (TrackGoAway(fWindow,where))
  419.                 HandleClose();
  420.             break;
  421.         
  422.         case inZoomIn:
  423.             if (TrackBox(fWindow,where,part))
  424.                 HandleZoomIn();
  425.             break;
  426.         
  427.         case inZoomOut:
  428.             if (TrackBox(fWindow,where,part))
  429.                 HandleZoomOut();
  430.             break;
  431.     }
  432. }
  433.  
  434.  
  435.  
  436.  
  437.  
  438. void BaseWindow::DoUpdate(void)
  439. {
  440.     QDContext    context(fWindow);
  441.     
  442.     
  443.     BeginUpdate((GrafPtr)fWindow);
  444.     HandleDraw();
  445.     EndUpdate((GrafPtr)fWindow);
  446. }
  447.  
  448.  
  449.  
  450.  
  451.  
  452. void BaseWindow::DoUpdateCursor(Point mouse,UInt32 modifiers)
  453. {
  454.     QDContext    context(fWindow);
  455.     
  456.     
  457.     GlobalToLocal(&mouse);
  458.     HandleCursorUpdate(mouse,modifiers);
  459. }
  460.  
  461.  
  462.  
  463.  
  464.  
  465. void BaseWindow::DoIdleTime(EventRecord *event,Point mouse,UInt32 modifiers)
  466. {
  467.     QDContext    context(fWindow);
  468.     
  469.     
  470.     GlobalToLocal(&mouse);
  471.     HandleIdleTime(mouse,modifiers);
  472.     
  473.     if ((fFlags & kDialog) && IsDialogEvent(event))
  474.         DoDialogEvent(event);
  475. }
  476.  
  477.  
  478.  
  479.  
  480.  
  481. void BaseWindow::DoSetActivationState(Boolean isActive)
  482. {
  483.     QDContext    context(fWindow);
  484.     
  485.     
  486.     if (isActive)
  487.     {
  488.         fFlags |= kActive;
  489.         HandleActivate();
  490.     }
  491.     else
  492.     {
  493.         fFlags &= ~kActive;
  494.         HandleDeactivate();
  495.     }
  496. }
  497.  
  498.  
  499.  
  500.  
  501.  
  502. void BaseWindow::DoSetSuspensionState(EventRecord *event,Boolean isSuspended)
  503. {
  504.     if (fFlags & kFloater)
  505.     {
  506.         if (isSuspended)
  507.         {
  508.             if (((WindowPeek)fWindow)->visible)
  509.             {
  510.                 fFlags |= kSuspended;
  511.                 ::HideWindow(fWindow);
  512.             }
  513.         }
  514.         else
  515.         {
  516.             if (fFlags & kSuspended)
  517.             {
  518.                 fFlags &= ~kSuspended;
  519.                 ::ShowWindow(fWindow);
  520.             }
  521.         }
  522.     }
  523.     else
  524.     {
  525.         if (isSuspended)
  526.         {
  527.             if (fFlags & kActive)
  528.             {
  529.                 fFlags |= kSuspended;
  530.                 DoSetActivationState(false);
  531.             }
  532.         }
  533.         else
  534.         {
  535.             if (fFlags & kSuspended)
  536.             {
  537.                 fFlags &= ~kSuspended;
  538.                 DoSetActivationState(true);
  539.             }
  540.         }
  541.     }
  542. }
  543.  
  544.  
  545.  
  546.  
  547.  
  548. Boolean BaseWindow::HandleGetParam(OSType param,SInt32 *value)
  549. {
  550.     switch(param)
  551.     {
  552.         case 'type':
  553.             *value = 'base';
  554.             return true;
  555.             break;
  556.         
  557.         default:
  558.             return false;
  559.             break;
  560.     }
  561. }
  562.  
  563.  
  564.  
  565.  
  566.  
  567. Boolean BaseWindow::HandleSetParam(OSType param,SInt32 value)
  568. {
  569.     switch(param)
  570.     {
  571.         default:
  572.             return false;
  573.             break;
  574.     }
  575. }
  576.  
  577.  
  578.  
  579.  
  580.  
  581. void BaseWindow::HandleClose(void)
  582. {
  583.     
  584. }
  585.  
  586.  
  587.  
  588.  
  589.  
  590. void BaseWindow::HandleZoomIn(void)
  591. {
  592.     
  593. }
  594.  
  595.  
  596.  
  597.  
  598.  
  599. void BaseWindow::HandleZoomOut(void)
  600. {
  601.     
  602. }
  603.  
  604.  
  605.  
  606.  
  607.  
  608. void BaseWindow::HandleDrag(Point start)
  609. {
  610.     Point    oldPos,newPos;
  611.     
  612.     
  613.     oldPos.h = fWindow->portRect.left;
  614.     oldPos.v = fWindow->portRect.top;
  615.     LocalToGlobal(&oldPos);
  616.     
  617.     DragWindow(fWindow,start,&qd.screenBits.bounds);
  618.     
  619.     newPos.h = fWindow->portRect.left;
  620.     newPos.v = fWindow->portRect.top;
  621.     LocalToGlobal(&newPos);
  622.     
  623.     if ((oldPos.h != newPos.h) || (oldPos.v != newPos.v))
  624.         HandleMove(newPos);
  625. }
  626.  
  627.  
  628.  
  629.  
  630.  
  631. void BaseWindow::HandleMove(Point where)
  632. {
  633.     
  634. }
  635.  
  636.  
  637.  
  638.  
  639.  
  640. void BaseWindow::HandleGrow(Point start)
  641. {
  642.     Rect    limits;
  643.     UInt32    dimensions;
  644.     
  645.     
  646.     limits.top = 64;
  647.     limits.left = 64;
  648.     limits.right = qd.screenBits.bounds.right;
  649.     limits.bottom = qd.screenBits.bounds.bottom;
  650.     
  651.     if (0 != (dimensions = GrowWindow(fWindow,start,&limits)))
  652.         HandleResize((dimensions >> 16),(dimensions & 0xFFFF));
  653. }
  654.  
  655.  
  656.  
  657.  
  658.  
  659. void BaseWindow::HandleResize(UInt32 height,UInt32 width)
  660. {
  661.     SizeWindow(fWindow,width,height,false);
  662.     InvalRect(&fWindow->portRect);
  663. }
  664.  
  665.  
  666.  
  667.  
  668.  
  669. void BaseWindow::HandleKey(UInt32 key,UInt32 modifiers)
  670. {
  671.     
  672. }
  673.  
  674.  
  675.  
  676.  
  677.  
  678. void BaseWindow::HandleClick(Point where,UInt32 modifiers)
  679. {
  680.     
  681. }
  682.  
  683.  
  684.  
  685.  
  686.  
  687. void BaseWindow::HandleActivate(void)
  688. {
  689.     
  690. }
  691.  
  692.  
  693.  
  694.  
  695.  
  696. void BaseWindow::HandleDeactivate(void)
  697. {
  698.     
  699. }
  700.  
  701.  
  702.  
  703.  
  704.  
  705. void BaseWindow::HandleCursorUpdate(Point mouse,UInt32 modifiers)
  706. {
  707.     
  708. }
  709.  
  710.  
  711.  
  712.  
  713.  
  714. void BaseWindow::HandleIdleTime(Point mouse,UInt32 modifiers)
  715. {
  716.     
  717. }
  718.  
  719.  
  720.  
  721.  
  722.  
  723. void BaseWindow::HandleDraw(void)
  724. {
  725.     
  726. }
  727.  
  728.  
  729.  
  730.  
  731.  
  732. BaseDialog::BaseDialog(UInt32 dialogID,Boolean isModal)
  733. {
  734.     fDialog = ::GetNewDialog(dialogID,NULL,(WindowPtr)-1L);
  735.     if (fDialog != NULL)
  736.     {
  737.         fFlags = isModal ? (kDialog | kModal) : kDialog;
  738.         fWindow = (WindowPtr)fDialog;
  739.         gWindowManager->DoAddWindow(this);
  740.         SelectWindow(fWindow);
  741.     }
  742. }
  743.  
  744.  
  745.  
  746.  
  747.  
  748. BaseDialog::~BaseDialog(void)
  749. {
  750.     if (fDialog != NULL)
  751.     {
  752.         gWindowManager->DoDeleteWindow(this);
  753.         DisposeDialog(fDialog);
  754.         fDialog = NULL;
  755.         fWindow = NULL;
  756.     }
  757. }
  758.  
  759.  
  760.  
  761.  
  762.  
  763. void BaseDialog::DoDialogEvent(EventRecord *event)
  764. {
  765.     QDContext    context(fWindow);
  766.     
  767.     
  768.     // We don't do any special preprocessing of
  769.     // events (yet) so just pass it straight thru
  770.     HandleDialogEvent(event);
  771. }
  772.  
  773.  
  774.  
  775.  
  776.  
  777. void BaseDialog::HandleDialogEvent(EventRecord *event)
  778. {
  779.     DialogPtr    dialog;
  780.     short        item;
  781.     
  782.     
  783.     if (HandleDialogEventFilter(event))
  784.     {
  785.         if (DialogSelect(event,&dialog,&item))
  786.             HandleDialogItemhit(item);
  787.         
  788.         // We have to check here to see if we've been deleted
  789.         // because HandleDialogItemhit might have been a hit to
  790.         // the OK or Cancel button.
  791.         if (fDialog != NULL)
  792.         {
  793.             // Automagically handle the hiliting
  794.             // and updating of the OK button
  795.             switch(event->what)
  796.             {
  797.                 case keyDown:
  798.                 case keyUp:
  799.                 case mouseDown:
  800.                 case mouseUp:
  801.                     // Only query the OK button state if something
  802.                     // happened that could have possibly changed it
  803.                     SetOKState(HandleOKButtonHiliteQuery());
  804.                     break;
  805.                 
  806.                 case updateEvt:
  807.                     DrawThickOutline(kOKButtonID);
  808.                     break;
  809.             }
  810.         }
  811.     }
  812. }
  813.  
  814.  
  815.  
  816.  
  817.  
  818. Boolean BaseDialog::HandleDialogEventFilter(EventRecord *event)
  819. {
  820.     ControlHandle    control;
  821.     short            type;
  822.     Rect            box;
  823.     
  824.     
  825.     // Filter out command/option/control keys
  826.     if (event->what == keyDown && (event->modifiers & (cmdKey | optionKey | controlKey)))
  827.         return false;
  828.     
  829.     switch(event->what)
  830.     {
  831.         case keyDown:
  832.         case autoKey:
  833.             switch(charCodeMask & event->message)
  834.             {
  835.                 case 0x0D:    // RETURN
  836.                     GetDialogItem(fDialog,kOKButtonID,&type,(Handle*)&control,&box);
  837.                     if ((type == 4) && (control[0]->contrlHilite == 0))
  838.                     {
  839.                         AnimateButtonPress(kOKButtonID);
  840.                         HandleDialogItemhit(kOKButtonID);
  841.                         return false;
  842.                     }
  843.                     break;
  844.                 
  845.                 case 0x1B:    // ESC
  846.                     GetDialogItem(fDialog,kCancelButtonID,&type,(Handle*)&control,&box);
  847.                     if ((type == 4) && (control[0]->contrlHilite == 0))
  848.                     {
  849.                         AnimateButtonPress(kCancelButtonID);
  850.                         HandleDialogItemhit(kCancelButtonID);
  851.                         return false;
  852.                     }
  853.                     break;
  854.             }
  855.             break;
  856.     }
  857.     
  858.     // Continue processing event
  859.     return true;
  860. }
  861.  
  862.  
  863.  
  864.  
  865.  
  866. void BaseDialog::HandleDialogItemhit(short item)
  867. {
  868.     // Default behavior for OK and Cancel
  869.     // button hits are to dismiss the dialog
  870.     switch(item)
  871.     {
  872.         case kOKButtonID:
  873.         case kCancelButtonID:
  874.             delete this;
  875.             break;
  876.     }
  877. }
  878.  
  879.  
  880.  
  881.  
  882.  
  883. Boolean BaseDialog::HandleOKButtonHiliteQuery(void)
  884. {
  885.     // Default behavior is to have a
  886.     // hilited and active OK button
  887.     return true;
  888. }
  889.  
  890.  
  891.  
  892.  
  893.  
  894. void BaseDialog::DrawThickOutline(short item)
  895. {
  896.     QDContext        context(fWindow);
  897.     ControlHandle    control;
  898.     short            type;
  899.     Rect            box;
  900.     
  901.     
  902.     // Draw a thick border around an item (default button outline)
  903.     GetDialogItem(fDialog,item,&type,(Handle*)&control,&box);
  904.     if (type == 4)
  905.     {
  906.         InsetRect(&box,-4,-4);
  907.         
  908.         if (control[0]->contrlHilite == 255)
  909.             PenPat(&qd.gray);
  910.         
  911.         PenSize(3,3);
  912.         FrameRoundRect(&box,16,16);
  913.     }
  914. }
  915.  
  916.  
  917.  
  918.  
  919.  
  920. void BaseDialog::SetOKState(Boolean isActive)
  921. {
  922.     ControlHandle    control;
  923.     short            type;
  924.     Rect            box;
  925.     
  926.     
  927.     // (De)Hilite the OK button to show its (in)active state
  928.     GetDialogItem(fDialog,kOKButtonID,&type,(Handle*)&control,&box);
  929.     if (type == 4)
  930.     {
  931.         if (isActive)
  932.         {
  933.             if (control[0]->contrlHilite == 255)
  934.             {
  935.                 HiliteControl(control,0);
  936.                 DrawThickOutline(kOKButtonID);
  937.             }
  938.         }
  939.         else
  940.         {
  941.             if (control[0]->contrlHilite != 255)
  942.             {
  943.                 HiliteControl(control,255);
  944.                 DrawThickOutline(kOKButtonID);
  945.             }
  946.         }
  947.     }
  948. }
  949.  
  950.  
  951.  
  952.  
  953.  
  954. void BaseDialog::AnimateButtonPress(short item)
  955. {
  956.     ControlHandle    control;
  957.     UInt32            ticks;
  958.     short            type;
  959.     Rect            box;
  960.     
  961.     
  962.     // Make it appear to the user that a button was pressed
  963.     GetDialogItem(fDialog,item,&type,(Handle*)&control,&box);
  964.     if ((type == 4) && (control[0]->contrlHilite == 0))
  965.     {
  966.         HiliteControl(control,kControlButtonPart);
  967.         Delay(10,&ticks);
  968.         HiliteControl(control,0);
  969.     }
  970. }
  971.  
  972.  
  973.  
  974.  
  975.  
  976. void BaseDialog::GetItemText(short item,char *text)
  977. {
  978.     Handle    data;
  979.     short    type;
  980.     Rect    rect;
  981.     Str255    pstr;
  982.     
  983.     
  984.     // Get the text of a static text item or an
  985.     // edit text item and return it as a c string
  986.     GetDialogItem(fDialog,item,&type,&data,&rect);
  987.     if ((type == statText) || (type == editText))
  988.         GetDialogItemText(data,pstr);
  989.     else
  990.         pstr[0] = '\0';
  991.     
  992.     pstr[1 + pstr[0]] = '\0';
  993.     strcpy(text,(char*)&pstr[1]);
  994. }
  995.  
  996.  
  997.  
  998.  
  999.  
  1000. int BaseDialog::GetItemTextAsDecimal(short item)
  1001. {
  1002.     char    text[256];
  1003.     
  1004.     
  1005.     // Get the text of a static text item or an edit
  1006.     // text item and return it as a decimal value
  1007.     GetItemText(item,text);
  1008.     return atoi(text);
  1009. }
  1010.  
  1011.  
  1012.  
  1013.  
  1014.  
  1015. void BaseDialog::SetItemText(short item,char *text)
  1016. {
  1017.     Handle    data;
  1018.     short    type;
  1019.     Rect    rect;
  1020.     Str255    pstr;
  1021.     
  1022.     
  1023.     // Set the text of a static text item
  1024.     // or an edit text item from a c string
  1025.     GetDialogItem(fDialog,item,&type,&data,&rect);
  1026.     if ((type == statText) || (type == editText))
  1027.     {
  1028.         pstr[0] = strlen(text);
  1029.         strcpy((char*)&pstr[1],text);
  1030.         SetDialogItemText(data,pstr);
  1031.     }
  1032. }
  1033.  
  1034.  
  1035.  
  1036.  
  1037.  
  1038. void BaseDialog::SetItemTextf(short item,char *format,...)
  1039. {
  1040.     va_list    args;
  1041.     char    text[256];
  1042.     
  1043.     
  1044.     // Set the text of a static text item or an edit
  1045.     // text item from a printf formatted specification
  1046.     va_start(args,format);
  1047.     vsprintf(text,format,args);
  1048.     va_end(args);
  1049.     
  1050.     SetItemText(item,text);
  1051. }
  1052.  
  1053.  
  1054.  
  1055.  
  1056.  
  1057. void BaseDialog::AppendItemText(short item,char *text)
  1058. {
  1059.     char    cur[256];
  1060.     
  1061.     
  1062.     // Append text to the end of a static text
  1063.     // item or an edit text item from a c string
  1064.     GetItemText(item,cur);
  1065.     strcat(cur,text);
  1066.     SetItemText(item,cur);
  1067. }
  1068.  
  1069.  
  1070.  
  1071.  
  1072.  
  1073. void BaseDialog::AppendItemTextf(short item,char *format,...)
  1074. {
  1075.     va_list    args;
  1076.     char    cur[256],text[256];
  1077.     
  1078.     
  1079.     // Append text to the end of a static text item or an
  1080.     // edit text item from a printf formatted specification
  1081.     va_start(args,format);
  1082.     vsprintf(text,format,args);
  1083.     va_end(args);
  1084.     
  1085.     GetItemText(item,cur);
  1086.     strcat(cur,text);
  1087.     SetItemText(item,cur);
  1088. }
  1089.